package com.java01.string.encoding;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

public class ByteArrayToString {

	public static void main(String[] args) {
		File file = new File("D:/word.txt");
		InputStream is = null;
		
		try {
			is = new FileInputStream(file);
			byte[] buffer = new byte[1024];
			int length;
			while((length=is.read(buffer))!=-1){
				//use a specific encoding
				System.out.println("Big5>>"+new String(buffer,0,length,"Big5")); //Traditional Chinese
				System.out.println();
				System.out.println("GB2312>>"+new String(buffer,0,length,"GB2312")); //Simplified Chinese
				System.out.println();
				System.out.println("JIS>>"+new String(buffer,0,length,"JIS")); //Japanese
				System.out.println();
				System.out.println("UTF-8>>"+new String(buffer,0,length,"UTF-8")); //Unicode
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		if (is != null) {
			try {
				is.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
